# Maintainer: Wu Zhenyu <wuzy01@qq.com>
_realname=hyperfine

pkgbase=mingw-w64-$_realname
pkgname=$MINGW_PACKAGE_PREFIX-$_realname
pkgver=1.15.0
pkgrel=1
pkgdesc='A command-line benchmarking tool (mingw-w64)'
arch=(any)
mingw_arch=(mingw32 mingw64 ucrt64 clang64)
url='https://github.com/sharkdp/hyperfine'
makedepends=($MINGW_PACKAGE_PREFIX-rust)
license=('spdx:MIT OR Apache-2.0')
source=("$url/archive/v$pkgver.tar.gz")
sha256sums=('b1a7a11a1352cdb549cc098dd9caa6c231947cc4dd9cd91ec25072d6d2978172')

prepare() {
  cd "${_realname}-${pkgver}"

  cargo fetch --locked
}

build() {
  cd "$srcdir/$_realname-$pkgver"
  cargo build --release --frozen
}

check() {
  cd "$srcdir/$_realname-$pkgver"
  cargo test --release --frozen
}

package() {
  cd "$srcdir/$_realname-$pkgver"
  install -Dm644 "LICENSE-APACHE" "$pkgdir$MINGW_PREFIX/share/licenses/$_realname/LICENSE-APACHE"
  install -Dm644 "LICENSE-MIT" "$pkgdir$MINGW_PREFIX/share/licenses/$_realname/LICENSE-MIT"
  install -Dm755 "target/release/$_realname" "$pkgdir$MINGW_PREFIX/bin/$_realname"

  install -Dm644 target/release/build/hyperfine-*/out/hyperfine.bash "$pkgdir$MINGW_PREFIX/share/bash-completion/completions/hyperfine"
  install -Dm644 target/release/build/hyperfine-*/out/hyperfine.fish "$pkgdir$MINGW_PREFIX/share/fish/vendor_completions.d/hyperfine.fish"
  install -Dm644 target/release/build/hyperfine-*/out/_hyperfine "$pkgdir$MINGW_PREFIX/share/zsh/site-functions/_hyperfine"

  install -Dm644 doc/hyperfine.1 "$pkgdir$MINGW_PREFIX/share/man/man1/hyperfine.1"
}
